<!--商品-->
<template>
  <view class="goods-item" @click="handelClick" :key="keys">
    <image class="goods-img" :src="cover"></image>
    <view class="goods-info">
      <view class="name">{{name}}</view>
      <view v-if="degree" class="degree-background">
        <view class="degree" :style="{width: degreeLength}">已抢{{degree}}件</view>
      </view>
      <view class="bottom">
        <view class="price">￥{{price}}</view>
        <view :class="{btn:true, 'hasNotStarted': !state}"> 立即抢购 </view>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  props:{
    id:{
      type: Number,
      required: true
    },
    name: {
      type: String,
      required: true,
    },
    cover: {
      type: String,
      required: true
    },
    price: {
      type: String,
      required: true
    },
    degree: {
      type: Number,
    },
    stock:{
      type: Number,
    },
    keys:{
      type: Number,
    },
    state:{
      type: Boolean,
      defalut: false,
    },
  },
  data(){
    return {

    }
  },
  computed:{
    // 已强进度条长度
    degreeLength(){
      return 298 ;//* (this.degree / this.stock) + 'rpx';
    }
  },
  methods:{
    handelClick(){
      this.$emit('click')
    }
  }
}
</script>
<style lang="scss">
.hasNotStarted{
  background: #C0C0C0!important;
  color: #FFFFFF;
}
.goods-item{
  width: 698rpx;
  height: 222rpx;
  background: #FFFFFF;
  border-radius: 16rpx;
  display: flex;
  justify-content: space-between;
  padding: 20rpx;
  margin-bottom: 25rpx;

  .goods-img{
    width: 178rpx;
    height: 178rpx;
    background: #D8D8D8;
    border-radius: 10rpx;
  }

  .goods-info{
    width: 442rpx;
    margin-bottom: 30rpx;
    .name{
      width: 100%;
      height: 88rpx;
      font-size: 32rpx;
      font-weight: 400;
      color: #1D1E22;
      line-height: 44rpx;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
    }
    .degree-background{
      margin-top: 16rpx;
      width: 298rpx;
      height: 30rpx;
      background: #FFD8C7;
      border-radius: 26rpx;

      .degree{
        height: 30rpx;
        background: #FF9974;
        border-radius: 26rpx;
        line-height: 30rpx;
        font-size: 20rpx;
        color: #FFFFFF;
        text-align: center;
      }
    }

    .bottom{
      margin-top: 44rpx;
      display: flex;
      justify-content: space-between;
      .price{
        width: 50%;
        height: 56rpx;
        font-size: 40rpx;
        font-weight: 600;
        color: #EE5B25;
        line-height: 56rpx;
      }

      .btn{
        width: 150rpx;
        height: 52rpx;
        line-height: 52rpx;
        background: #EE5B25;
        border-radius: 14rpx;
        text-align: center;
        color: #FFFFFF;
        font-size: 24rpx;
        font-weight: 400;
      }
    }
  }
}
</style>
